﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System;
using System.Windows.Data;


namespace MissedMemo.MeatAndCheeseDisc.UIHelperClasses
{
    // Stolen from Petzold (p.633/4)

    public class FormattedTextConverter : IValueConverter
    {
        public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            string strFormat = parameter as string;

            if( strFormat == null )
                return value.ToString();

            else if( value is TimeSpan )
            {
                TimeSpan elapsedTime = (TimeSpan)value;
                return string.Format( strFormat, new DateTime(elapsedTime.Ticks) );
            }

            else return string.Format( strFormat, value );
        }


        public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )
        {
            throw new NotImplementedException();
        }
    }
}
